<?php
namespace plugin\entity_manager\src\exception;

/**
 * The MIT License
 *
 * Copyright (c) <year> <copyright holders>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @author Damiano Ciarla
 * @package plugin
 * @subpackage entity_manager/class/exception
 */
class EntityManagerException extends \Exception
{
	/**
	 * La colonna specificata non è presente nella entity che si sta analizzando
	 */
	const FIELD_NOT_FOUND_INTO_SELECT = 1;

	/**
	 * La colonna specificata non è presente nella entity che si sta analizzando
	 */
	const FIELD_NOT_FOUND_INTO_WHERE = 2;

	/**
	 * La colonna specificata non è presente nella entity che si sta analizzando
	 */
	const FIELD_NOT_FOUND_INTO_GROUP_BY = 3;

	/**
	 * La colonna specificata non è presente nella entity che si sta analizzando
	 */
	const FIELD_NOT_FOUND_INTO_ORDER_BY = 4;

	/**
	 * Nessun valore impostato della dichiarazione sql della select
	 */
	const NO_FIELD_SET = 5;

	/**
	 * L'operatore specificato per la condizione della where non è valido
	 */
	const INVALID_OPERATOR = 6;

	/**
	 * Il valore specificato nella condizione del group by non è valido
	 */
	const INVALID_ORDER_BY_VALUE = 7;

	/**
	 * Nessun valore è stato specificato nella group by
	 */
	const NO_GROUP_BY_SET = 8;

	/**
	 * Il tipo di campo non è una stringa valida
	 */
	const FIELD_TYPE_IS_NOT_A_STRING = 9;

	/**
	 * Il tipo di campo non è una stringa valida
	 */
	const INCORRECT_ORDER_BY_VALUE = 10;

	/**
	 * La entity che si sta cercando di caricare non è presente nella cartella dei model
	 */
	const LOAD_ENTITY_BASE_NOT_FOUND = 11;

	/**
	 * La entity che si sta cercando di caricare non è presente nella cartella dei model
	 */
	const LOAD_ENTITY_EXTENDED_NOT_FOUND = 12;

	/**
	 * La cartella contenente i model non esiste
	 */
	const FOLDER_MODEL_NOT_EXISTS = 13;

	/**
	 * La cartella contenente i model non è scrivibile
	 */
	const FOLDER_MODEL_IS_NOT_WRITABLE = 14;

	/**
	 * Entity precedente non trovata
	 */
	const PREVIUS_ENTITY_NOT_FOUND = 15;

	/**
	 * Nessuna relazione trovata con la Entity precedente
	 */
	const NO_RELATIONSHIP_WITH_PREVIUS_ENTITY = 16;

	/**
	 * La condizione della join non è valida
	 */
	const CUSTOM_CONDITION_JOIN_NOT_VALID = 17;
	
	/**
	 * La condizione della join tabella precedente non trovata
	 */
	const CUSTOM_CONDITION_JOIN_PREVIOUS_TABLE_NOT_FOUND = 19;
	
	/**
	 * La condizione della join campo precedente non trovato
	 */
	const CUSTOM_CONDITION_JOIN_PREVIOUS_FIELD_NOT_FOUND = 20;
	
	/**
	 * La condizione della join tabella corrente non trovata
	 */
	const CUSTOM_CONDITION_JOIN_CURRENT_TABLE_NOT_FOUND = 21;
	
	/**
	 * La condizione della join campo corrente non trovato
	 */
	const CUSTOM_CONDITION_JOIN_CURRENT_FIELD_NOT_FOUND = 22;
	
	/**
	 * Tabella non presente nel risultato della join
	 */
	const TABLE_NOT_FOUND_INTO_JOIN_COLLECTION_DATA = 23;

	public function __construct($params, $code)
	{
		switch($code)
		{
			case self::FIELD_NOT_FOUND_INTO_SELECT :
				$message = sprintf("Field '%s' not found into sql select statement of the entity '%s'", $params[0], $params[1]);
				break;

			case self::FIELD_NOT_FOUND_INTO_GROUP_BY :
				$message = sprintf("Field '%s' not found into sql group by statement of the entity '%s'", $params[0], $params[1]);
				break;

			case self::FIELD_NOT_FOUND_INTO_WHERE :
				$message = sprintf("Field '%s' not found into sql where statement of the entity '%s'", $params[0], $params[1]);
				break;

			case self::FIELD_NOT_FOUND_INTO_ORDER_BY :
				$message = sprintf("Field '%s' not found into sql order by statement of the entity '%s'", $params[0], $params[1]);
				break;

			case self::NO_FIELD_SET :
				$message = sprintf("No field set into sql select statement for the entity: '%s'", $params);
				break;

			case self::INVALID_OPERATOR :
				$message = sprintf("Invalid operator '%s' into sql where statement", $params);
				break;

			case self::INVALID_ORDER_BY_VALUE :
				$message = sprintf("Invalid order by value '%s'", $params);
				break;

			case self::NO_GROUP_BY_SET :
				$message = sprintf("No group by set for the entity: '%s'", $params);
				break;

			case self::FIELD_TYPE_IS_NOT_A_STRING :
				$message = sprintf("No field '%s' is not a string", $params);
				break;

			case self::INCORRECT_ORDER_BY_VALUE :
				$message = "The value in the order by clause must be 'ASC' or 'DESC'";
				break;

			case self::LOAD_ENTITY_BASE_NOT_FOUND :
				$message = sprintf("The entity 'base%s' not found into '%s/base' folder", $params[0], $params[1]);
				break;

			case self::LOAD_ENTITY_EXTENDED_NOT_FOUND :
				$message = sprintf("The entity '%s' not found into '%s' folder", $params[0], $params[1]);
				break;

			case self::FOLDER_MODEL_NOT_EXISTS :
				$message = sprintf("The folder '%s' not exists", $params);
				break;

			case self::FOLDER_MODEL_IS_NOT_WRITABLE :
				$message = sprintf("The folder '%s' is not writable", $params);
				break;

			case self::PREVIUS_ENTITY_NOT_FOUND :
				$message = sprintf("The entity '%s' not found in the previous list of entities", $params);
				break;

			case self::NO_RELATIONSHIP_WITH_PREVIUS_ENTITY :
				$message = sprintf("Relationship not found with '%s' and '%s' entity", $params[0], $params[1]);
				break;

			case self::CUSTOM_CONDITION_JOIN_NOT_VALID :
				$message = sprintf("The custom condition '%s' for the join is not valid", $params);
				break;

			case self::CUSTOM_CONDITION_JOIN_PREVIOUS_TABLE_NOT_FOUND :
				$message = sprintf("Not found the previous table '%s' in the custom condition '%s'", $params[0], $params[1]);
				break;

			case self::CUSTOM_CONDITION_JOIN_PREVIOUS_FIELD_NOT_FOUND :
				$message = sprintf("Not found the previous field '%s' in the custom condition '%s'", $params[0], $params[1]);
				break;

			case self::CUSTOM_CONDITION_JOIN_CURRENT_TABLE_NOT_FOUND :
				$message = sprintf("Not found the current table '%s' in the custom condition '%s'", $params[0], $params[1]);
				break;

			case self::CUSTOM_CONDITION_JOIN_CURRENT_FIELD_NOT_FOUND :
				$message = sprintf("Not found the current field '%s' in the custom condition '%s'", $params[0], $params[1]);
				break;

			case self::TABLE_NOT_FOUND_INTO_JOIN_COLLECTION_DATA :
				$message = sprintf("Table '%s' not found into JoinCollectionData object", $params);
				break;

			default :
				$message = "Undefined entity manager error";
				break;
		}

		parent::__construct($message, $code);
	}
}
?>